package com.j48.entrancegurad.service.impl;

import com.j48.entrancegurad.mapper.P_CMapper;
import com.j48.entrancegurad.model.P_C;
import com.j48.entrancegurad.model.Character;
import com.j48.entrancegurad.model.Power;
import com.j48.entrancegurad.service.IP_CService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class P_CService implements IP_CService {

    @Autowired
    private P_CMapper p_cMapper;

    /**
     * 按角色查询角色权限关系
     * @param character 查询的角色
     * @return
     */
    @Override
    public ArrayList<P_C> select(Character character) {
        P_C p_c=new P_C();
        p_c.setP_c_character_id(character.getCharacter_id());
        ArrayList<P_C> p_cs=p_cMapper.select(p_c);
        return p_cs;
    }

    /**
     * 删除角色-权限
     * @param p_c
     * @return 是否删除成功
     */
    public boolean deleteBycharacterid(P_C p_c){
        int i=p_cMapper.deleteByCharacterid(p_c);
        if(i>0){
            return true;
        }
        return false;
    }

    /**
     * 添加权限
     * @param p_c
     * @return 被影响的行数
     */
    public int addP_c(P_C p_c){
        return p_cMapper.insert(p_c);
    }

    /**
     * 通过角色ID查询权限
     * @param p_c
     * @return
     */
    public ArrayList<P_C> selectall(P_C p_c){
        return p_cMapper.select(p_c);
    }

    /**
     * 删除
     * @param p_c
     * @return
     */
    public int deletep_c(P_C p_c){
        return p_cMapper.deleteByCharacterid(p_c);
    }
}
